home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / recode.lha / recode-3.2.4 / ascicdcn.c < prev    next >
C/C++ Source or Header  |  1992-08-26  |  4KB  |  174 lines

  1. /* Conversion of files between different charsets and usages.
  2.    Copyright (C) 1990 Free Software Foundation, Inc.
  3.    Francois Pinard <pinard@iro.umontreal.ca>, 1988.
  4.  
  5.    This program is free software; you can redistribute it and/or modify
  6.    it under the terms of the GNU General Public License as published by
  7.    the Free Software Foundation; either version 2, or (at your option)
  8.    any later version.
  9.  
  10.    This program is distributed in the hope that it will be useful, but
  11.    WITHOUT ANY WARRANTY; without even the implied warranty of
  12.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.    General Public License for more details.
  14.  
  15.    You should have received a copy of the GNU General Public License
  16.    along with this program; if not, write to the Free Software
  17.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19.  
  20. #define STEP    ascii_cdcnos
  21. #include <stdio.h>
  22. #include "common.h"
  23.  
  24. static const char *translation_table[128] =
  25.   {
  26.     "^5",            /* \000 */
  27.     "^6",            /* \001 */
  28.     "^7",            /* \002 */
  29.     "^8",            /* \003 */
  30.     "^9",            /* \004 */
  31.     "^+",            /* \005 */
  32.     "^-",            /* \006 */
  33.     "^*",            /* \007 */
  34.     "^/",            /* \010 */
  35.     "^(",            /* \011 */
  36.     "^)",            /* \012 */
  37.     "^$",            /* \013 */
  38.     "^=",            /* \014 */
  39.     "^ ",            /* \015 */
  40.     "^,",            /* \016 */
  41.     "^.",            /* \017 */
  42.     "^#",            /* \020 */
  43.     "^[",            /* \021 */
  44.     "^]",            /* \022 */
  45.     "^%",            /* \023 */
  46.     "^\"",            /* \024 */
  47.     "^_",            /* \025 */
  48.     "^!",            /* \026 */
  49.     "^&",            /* \027 */
  50.     "^'",            /* \030 */
  51.     "^?",            /* \031 */
  52.     "^<",            /* \032 */
  53.     "^>",            /* \033 */
  54.     "^@",            /* \034 */
  55.     "^\\",            /* \035 */
  56.     "^^",            /* \036 */
  57.     "^;",            /* \037 */
  58.     " ",            /* \040 */
  59.     "!",            /* \041 */
  60.     "\"",            /* \042 */
  61.     "#",            /* \043 */
  62.     "$",            /* \044 */
  63.     "%",            /* \045 */
  64.     "&",            /* \046 */
  65.     "'",            /* \047 */
  66.     "(",            /* \050 */
  67.     ")",            /* \051 */
  68.     "*",            /* \052 */
  69.     "+",            /* \053 */
  70.     ",",            /* \054 */
  71.     "-",            /* \055 */
  72.     ".",            /* \056 */
  73.     "/",            /* \057 */
  74.     "0",            /* \060 */
  75.     "1",            /* \061 */
  76.     "2",            /* \062 */
  77.     "3",            /* \063 */
  78.     "4",            /* \064 */
  79.     "5",            /* \065 */
  80.     "6",            /* \066 */
  81.     "7",            /* \067 */
  82.     "8",            /* \070 */
  83.     "9",            /* \071 */
  84.     "@D",            /* \072 */
  85.     ";",            /* \073 */
  86.     "<",            /* \074 */
  87.     "=",            /* \075 */
  88.     ">",            /* \076 */
  89.     "?",            /* \077 */
  90.     "@A",            /* \100 */
  91.     "A",            /* \101 */
  92.     "B",            /* \102 */
  93.     "C",            /* \103 */
  94.     "D",            /* \104 */
  95.     "E",            /* \105 */
  96.     "F",            /* \106 */
  97.     "G",            /* \107 */
  98.     "H",            /* \110 */
  99.     "I",            /* \111 */
  100.     "J",            /* \112 */
  101.     "K",            /* \113 */
  102.     "L",            /* \114 */
  103.     "M",            /* \115 */
  104.     "N",            /* \116 */
  105.     "O",            /* \117 */
  106.     "P",            /* \120 */
  107.     "Q",            /* \121 */
  108.     "R",            /* \122 */
  109.     "S",            /* \123 */
  110.     "T",            /* \124 */
  111.     "U",            /* \125 */
  112.     "V",            /* \126 */
  113.     "W",            /* \127 */
  114.     "X",            /* \130 */
  115.     "Y",            /* \131 */
  116.     "Z",            /* \132 */
  117.     "[",            /* \133 */
  118.     "\\",            /* \134 */
  119.     "]",            /* \135 */
  120.     "@B",            /* \136 */
  121.     "_",            /* \137 */
  122.     "@G",            /* \140 */
  123.     "^A",            /* \141 */
  124.     "^B",            /* \142 */
  125.     "^C",            /* \143 */
  126.     "^D",            /* \144 */
  127.     "^E",            /* \145 */
  128.     "^F",            /* \146 */
  129.     "^G",            /* \147 */
  130.     "^H",            /* \150 */
  131.     "^I",            /* \151 */
  132.     "^J",            /* \152 */
  133.     "^K",            /* \153 */
  134.     "^L",            /* \154 */
  135.     "^M",            /* \155 */
  136.     "^N",            /* \156 */
  137.     "^O",            /* \157 */
  138.     "^P",            /* \160 */
  139.     "^Q",            /* \161 */
  140.     "^R",            /* \162 */
  141.     "^S",            /* \163 */
  142.     "^T",            /* \164 */
  143.     "^U",            /* \165 */
  144.     "^V",            /* \166 */
  145.     "^W",            /* \167 */
  146.     "^X",            /* \170 */
  147.     "^Y",            /* \171 */
  148.     "^Z",            /* \172 */
  149.     "^0",            /* \173 */
  150.     "^1",            /* \174 */
  151.     "^2",            /* \175 */
  152.     "^3",            /* \176 */
  153.     "^4",            /* \177 */
  154.   };
  155.  
  156. void
  157. STEP (FILE *input_file, FILE *output_file)
  158. {
  159.   int input_char;        /* current character */
  160.   const char *output_string;    /* translated characters */
  161.  
  162.   while (input_char = getc (input_file), input_char != EOF)
  163.     if (input_char == '\n')
  164.       putc ('\n', output_file);
  165.     else if (input_char & 0200)
  166.       putc (input_char, output_file);
  167.     else if (output_string = translation_table[input_char], output_string)
  168.       while (*output_string)
  169.     {
  170.       putc (*output_string, output_file);
  171.       output_string++;
  172.     }
  173. }
  174.